package com.cjm.algorithm.dp;

public class Ti1143 {
    public static void main(String[] args) {

    }

    public int longestCommonSubsequence(String text1, String text2) {
        int[][] dp = new int[text1.length() + 1][text2.length() + 1];
        for (int i = 1; i < text1.length() + 1; i++) {
            for (int k = 1; k < text2.length() + 1; k++) {
                if (text1.charAt(i - 1) == text2.charAt(k - 1)) {
                    dp[i][k] = dp[i - 1][k - 1] + 1;
                } else {
                    dp[i][k] = Math.max(dp[i - 1][k], dp[i][k - 1]);
                }
            }
        }
        return dp[text1.length()][text2.length()];
    }
}
